package com.yuncheng.spcyApi.spcyService;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yuncheng.entity.YcSysUser;
import com.yuncheng.spcyApi.alog.utils.StringEmptyUtils;
import com.yuncheng.spcyApi.constant.jcy.JcyLxjhConstant;
import com.yuncheng.spcyApi.constant.jcy.JcyLxpgDcbConstant;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.mapper.SpcyPxJbxxMapper;
import com.yuncheng.spcyApi.service.*;
import com.yuncheng.spcyApi.utils.DateConvert;
import com.yuncheng.spcyApi.utils.GetUuIdUtils;
import com.yuncheng.spcyApi.utils.StringPatternUtils;
import com.yuncheng.spcyApi.vo.jcy.JcyLxUserVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import utils.DateConversionUtils;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

/**
 * 检查员遴选-培训-评估调查表
 * @author hua
 */
@Component(value = "jcyLxpgdjbService")
public class JcyLxpgdjbService {
    private static final Logger log = LoggerFactory.getLogger(JcyLxpgdjbService.class);

    @Resource
    private ISpcyJcyLxjxpgdcbService spcyJcyLxjxpgdcbService;

    @Resource
    private ISpcyJcyLxjxpgxxService spcyJcyLxjxpgxxService;

    @Resource
    private ISpcyJcyLxjsjxpjService spcyJcyLxjsjxpjService;

    @Resource
    private ISpcyJcyLxpxlsService spcyJcyLxpxlsService;

    @Resource
    private SpcyPxJbxxMapper spcyPxJbxxMapper;

    @Resource
    private ISpcyPxJbxxService spcyPxJbxxService;

    @Resource
    private ISpcyJcyLxqdcsService spcyJcyLxqdcsService;

    @Resource
    private IYcSysUserService sysUserService;

    @Resource
    private ISpcyPxCjryService spcyPxCjryService;

    @Autowired
    @Qualifier("asyncNormalTask")
    private Executor executor;

    /**
     * 初始化-检查员-教学评估调查表
     */
    public Map initJcyJxpgdcb(String flxjhid, String userid){
        if (StringUtils.isBlank(flxjhid)){
            throw new BusinessException("参数为空！");
        }

        if (StringUtils.isBlank(userid)){
            throw new BusinessException("人员参数为空！");
        }

        SpcyPxCjry cjry = spcyPxCjryService.selectLxCjryByLxjhId(flxjhid, userid);
        if (cjry == null){
            throw new BusinessException("评估失败，您不属于本次培训人员！");
        }

        if (StringUtils.isBlank(cjry.getFsjshzt()) || !cjry.getFsjshzt().equals(JcyLxjhConstant.JCYLX_CJRY_SJSHZT_SHTG)){
            throw new BusinessException("评估失败，您当前不符合本次评估条件！需报名并通过审核才可进行评估！");
        }

        /*// 签到场次
        int qdcsSize = spcyJcyLxqdcsService.list(new LambdaQueryWrapper<SpcyJcyLxqdcs>()
                .eq(SpcyJcyLxqdcs::getFlxjhid, flxjhid)).size();
        // 签到场次次数
        int qdjlSize = spcyJcyLxqdcsService.selectLxqdjlByUser(flxjhid, userid).size();
        if (qdcsSize > qdjlSize){
            throw new BusinessException("请先签到完，再进行评价！");
        }*/

        List<SpcyJcyLxjxpgdcb> djbList = spcyJcyLxjxpgdcbService.list(new LambdaQueryWrapper<SpcyJcyLxjxpgdcb>()
                .eq(SpcyJcyLxjxpgdcb::getFlxjhid, flxjhid)
                .eq(SpcyJcyLxjxpgdcb::getFpjrid, userid));
        if (CollectionUtil.isNotEmpty(djbList)){
            return getJcyJxpgDcb(flxjhid, userid, null, null, null);
        }

        // 用户
        YcSysUser user = sysUserService.getById(userid);
        if (user == null){
            throw new BusinessException("没有相匹配的人员数据！");
        }

        // 调查表
        SpcyJcyLxjxpgdcb dcb = new SpcyJcyLxjxpgdcb();
        dcb.setId(GetUuIdUtils.ReplaceUuId());
        dcb.setFlxjhid(flxjhid);
        dcb.setFpjrid(userid);
        dcb.setFpjrxm(user.getRealname());
        dcb.setFyjjy("无");


        /** 初始化调查表选项 */
        List<SpcyJcyLxjxpgxx> dcbxxList = new ArrayList<>();
        CompletableFuture<String> futureDcbxxList = CompletableFuture.supplyAsync(() -> {

            String[] pgdlStrings = JcyLxpgDcbConstant.Dcb_Pgdl_List.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

            String[] pgmbBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxmb_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
            String[] pgmbNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxmb_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

            String[] pxfaBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxfa_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
            String[] pxfaNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxfa_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

            String[] pxszBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxsz_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
            String[] pxszNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxsz_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

            String[] pxnrBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxnr_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
            String[] pxnrNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxnr_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

            String[] pxxsBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxxs_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
            String[] pxxsNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxxs_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

            String[] pxzlBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxzl_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
            String[] pxzlNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxzl_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

            String[] xczzBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Xczz_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
            String[] xczzNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Xczz_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

            String[] pxbzBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxbz_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
            String[] pxbzNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxbz_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

            String[] xythBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Xyth_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
            String[] xythNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Xyth_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

            /** 初始化调查表选项 */
            for (int i = 0; i < pgdlStrings.length; i++){
                String type = pgdlStrings[i];


                String[] dctBtStrings = null;
                String[] dctNrStrings = null;

                if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxmb)){
                    dctBtStrings = pgmbBtStrings;
                    dctNrStrings = pgmbNrStrings;

                }
                else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxfa)){
                    dctBtStrings = pxfaBtStrings;
                    dctNrStrings = pxfaNrStrings;

                }
                else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxsz)){
                    dctBtStrings = pxszBtStrings;
                    dctNrStrings = pxszNrStrings;

                }
                else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxnr)){
                    dctBtStrings = pxnrBtStrings;
                    dctNrStrings = pxnrNrStrings;

                }
                else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxxs)){
                    dctBtStrings = pxxsBtStrings;
                    dctNrStrings = pxxsNrStrings;

                }
                else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxzl)){
                    dctBtStrings = pxzlBtStrings;
                    dctNrStrings = pxzlNrStrings;

                }
                else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Xczz)){
                    dctBtStrings = xczzBtStrings;
                    dctNrStrings = xczzNrStrings;

                }
                else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxbz)){
                    dctBtStrings = pxbzBtStrings;
                    dctNrStrings = pxbzNrStrings;

                }
                else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Xyth)){
                    dctBtStrings = xythBtStrings;
                    dctNrStrings = xythNrStrings;

                }

                if (dctBtStrings != null) {
                    for (int j=0; j<dctBtStrings.length; j++) {
                        SpcyJcyLxjxpgxx dcbxx = new SpcyJcyLxjxpgxx();
                        dcbxx.setId(GetUuIdUtils.ReplaceUuId());
                        dcbxx.setFlxjhid(flxjhid);
                        dcbxx.setFpgdcbid(dcb.getId());

                        dcbxx.setFpgdl(type);

                        dcbxx.setFpgbt(dctBtStrings[j]);
                        dcbxx.setFpgnr(dctNrStrings[j]);
                        dcbxx.setFpgjg(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My);

                        dcbxx.setCreateTime(new Date());

                        dcbxxList.add(dcbxx);
                    }
                }
            }

            return "1";
        }, executor);

        /** 培训老师 */
        List<SpcyJcyLxjsjxpj> dcbJsList = new ArrayList<>();

        CompletableFuture<String> futureDcbJsList = CompletableFuture.supplyAsync(() -> {

            List<String> djbJsxmList = new ArrayList<>();
            List<SpcyJcyLxpxls> pxlsList = spcyJcyLxpxlsService.getPxlsList(flxjhid);
            if (CollectionUtil.isNotEmpty(pxlsList)){
                for (SpcyJcyLxpxls pxls : pxlsList){

                    if (djbJsxmList.contains(pxls.getFjsxm())){
                        continue;
                    }

                    SpcyJcyLxjsjxpj jsjxpj = new SpcyJcyLxjsjxpj();
                    jsjxpj.setId(GetUuIdUtils.ReplaceUuId());
                    jsjxpj.setFpgdcbid(dcb.getId());
                    jsjxpj.setFpxlsid(pxls.getId());

                    jsjxpj.setFjxxg(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My);
                    jsjxpj.setFjjtczdnd(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My);
                    jsjxpj.setFjxjqyff(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My);
                    jsjxpj.setFjxnrzdx(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My);
                    jsjxpj.setFjxtd(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My);

                    jsjxpj.setCreateTime(new Date());
                    dcbJsList.add(jsjxpj);
                    djbJsxmList.add(pxls.getFjsxm());
                }
            }

            return "1";
        }, executor);

        CompletableFuture<Void> futureAllOf = CompletableFuture.allOf(futureDcbxxList, futureDcbJsList);
        try {
            futureAllOf.get();// 等待所有结果执行完成
        } catch (InterruptedException e) {
            log.error("[InterruptedException]初始化-检查员-教学评估调查表: {}",e.getMessage());
        } catch (ExecutionException e) {
            log.error("[ExecutionException]初始化-检查员-教学评估调查表: {}",e.getMessage());
        }

        spcyJcyLxjxpgdcbService.save(dcb);
        spcyJcyLxjxpgxxService.saveBatch(dcbxxList);

        if (CollectionUtil.isNotEmpty(dcbJsList)) {
            spcyJcyLxjsjxpjService.saveBatch(dcbJsList);
        }


        return getJcyJxpgDcb(flxjhid, userid, dcb, dcbxxList, dcbJsList);
    }

    /**
     *  获取-检查员-教学评估调查表
     */
    private Map getJcyJxpgDcb(String flxjhid, String userid, SpcyJcyLxjxpgdcb dcb, List<SpcyJcyLxjxpgxx> dcbxxList, List<SpcyJcyLxjsjxpj> pgjsList){

        Map resultMap = new HashMap<>();
        SpcyPxJbxx lxjh = spcyPxJbxxService.getById(flxjhid);

        String dcbid = "";

        // 调查表
        if (dcb == null) {
            List<SpcyJcyLxjxpgdcb> dcbList = spcyJcyLxjxpgdcbService.list(new LambdaQueryWrapper<SpcyJcyLxjxpgdcb>()
                    .eq(SpcyJcyLxjxpgdcb::getFpjrid, userid)
                    .eq(SpcyJcyLxjxpgdcb::getFlxjhid, flxjhid));
            if (CollectionUtil.isNotEmpty(dcbList)) {
                dcb = dcbList.get(0);
                dcbid = dcbList.get(0).getId();
            }
        }else {
            dcbid = dcb.getId();
        }

        // 调查表选项
        if (CollectionUtil.isEmpty(dcbxxList)) {
            dcbxxList = spcyJcyLxjxpgxxService.list(new LambdaQueryWrapper<SpcyJcyLxjxpgxx>()
                    .eq(SpcyJcyLxjxpgxx::getFpgdcbid, dcbid));
        }

        // 评估教师
        if (CollectionUtil.isEmpty(pgjsList)) {
            pgjsList = spcyJcyLxjsjxpjService.list(new LambdaQueryWrapper<SpcyJcyLxjsjxpj>()
                    .eq(SpcyJcyLxjsjxpj::getFpgdcbid, dcbid));
        }

        // 培训信息
        resultMap.put("px", initDcbPxbxxMap(lxjh));

        resultMap.put("dcb", dcb);

        /*resultMap.put("xxList", initDcbXxListMap(dcbxxList));
        resultMap.put("jsjxpjList", initDcbJsjxpjListMap(flxjhid, pgjsList));*/

        List<SpcyJcyLxjxpgxx> finalDcbxxList = dcbxxList;
        CompletableFuture<String> futureXxList = CompletableFuture.supplyAsync(() -> {
            resultMap.put("xxList", initDcbXxListMap(finalDcbxxList));

            return "1";
        }, executor);

        List<SpcyJcyLxjsjxpj> finalPgjsList = pgjsList;
        CompletableFuture<String> futureJsjxpjList = CompletableFuture.supplyAsync(() -> {
            resultMap.put("jsjxpjList", initDcbJsjxpjListMap(flxjhid, finalPgjsList));

            return "1";
        }, executor);

        CompletableFuture<Void> futureAllOf = CompletableFuture.allOf(futureXxList, futureJsjxpjList);
        try {
            futureAllOf.get();// 等待所有结果执行完成
        } catch (InterruptedException e) {
            log.error("[InterruptedException]获取-检查员-教学评估调查表: {}", e.getMessage());
        } catch (ExecutionException e) {
            log.error("[ExecutionException]获取-检查员-教学评估调查表: {}", e.getMessage());
        }

        return resultMap;
    }

    /** 构建培训表信息 */
    private Map initDcbPxbxxMap(SpcyPxJbxx lxjh){
        // 培训信息
        Map pxMap = new HashMap();
        pxMap.put("id", lxjh.getId());
        pxMap.put("pxbmc", lxjh.getFpxmc());
        pxMap.put("pxbzbdw", lxjh.getFzzdw());

        String pxsj = "";
        if (lxjh.getFpxkssj() != null){
            pxsj += DateConversionUtils.DateToString(lxjh.getFpxkssj());
        }
        if (lxjh.getFpxjssj() != null){
            pxsj += "-";
            pxsj += DateConversionUtils.DateToString(lxjh.getFpxjssj());
        }
        pxMap.put("pxsj", pxsj);

        return pxMap;
    }

    /** 构建调查表选项结构 */
    private List<Map> initDcbXxListMap(List<SpcyJcyLxjxpgxx> dcbxxList){
        List<Map> resultMapList = new ArrayList<>();

        if (CollectionUtil.isEmpty(dcbxxList)){
            return resultMapList;
        }

        String[] pgdlStrings = JcyLxpgDcbConstant.Dcb_Pgdl_List.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
        for (int order = 0; order < pgdlStrings.length; order++){
            Map dataMap = new HashMap();
            String type = pgdlStrings[order];
            dataMap.put("type", type);

            List<SpcyJcyLxjxpgxx> list = dcbxxList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getFpgdl()) && f.getFpgdl().equals(type))
                    .collect(Collectors.toList());
            dataMap.put("list", list);

            resultMapList.add(dataMap);
        }

        return resultMapList;
    }

    /**
     * 构建调查表-教师教学评价
     */
    private List<Map> initDcbJsjxpjListMap(String flxjhid, List<SpcyJcyLxjsjxpj> pgjsList){
        List<Map> jsjxpjList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(pgjsList)) {
            for (SpcyJcyLxjsjxpj pgjs : pgjsList) {
                SpcyJcyLxpxls pxls = spcyJcyLxpxlsService.getById(pgjs.getFpxlsid());

                Map jsjxpjMap = new HashMap();
                String name = "";

                List<Map> pxnrList = new ArrayList<>();
                if (pxls != null) {
                    name = pxls.getFjsxm();

                    pxnrList = initDcbJsjxPjNrListMap(pxnrList, flxjhid, name);
                }

                jsjxpjMap.put("name", name);
                jsjxpjMap.put("pxnrList", pxnrList);
                jsjxpjMap.put("pjnr", pgjs);

                jsjxpjList.add(jsjxpjMap);
            }
        }

        return jsjxpjList;
    }

    /**
     * 构建调查表-教师教学评价-教学内容
     * @param name 教师姓名
     */
    private List<Map> initDcbJsjxPjNrListMap(List<Map> pxnrList, String flxjhid, String name){
        if (StringUtils.isBlank(name)){
            return pxnrList;
        }
        List<SpcyJcyLxpxls> pxlsList = spcyJcyLxpxlsService.list(new LambdaQueryWrapper<SpcyJcyLxpxls>()
                .eq(SpcyJcyLxpxls::getFlxjhid, flxjhid)
                .eq(SpcyJcyLxpxls::getFjsxm, name));

        if (CollectionUtil.isNotEmpty(pxlsList)) {
            for (SpcyJcyLxpxls pxls2 : pxlsList) {
                SpcyJcyLxqdcs qdcs = spcyJcyLxqdcsService.getById(pxls2.getFlxqdccid());
                if (qdcs != null) {
                    Map pxnrMap = new HashMap();

                    String pxsj = "";
                    if (qdcs.getFccpxsj() != null) {
                        pxsj = DateConversionUtils.DateToString(qdcs.getFccpxsj());
                    }
                    pxsj += qdcs.getFqdccbt();

                    pxnrMap.put("pxsj", pxsj);
                    pxnrMap.put("jxnr", pxls2.getFjspxnr());
                    pxnrList.add(pxnrMap);
                }
            }
        }

        return pxnrList;
    }

    /**
     * 更新-评估调查表
     * @param buffer
     */
    public void updatePgDcb(SpcyJcyLxjxpgdcb buffer) throws InvocationTargetException, IllegalAccessException {

        if (StringUtils.isBlank(buffer.getId())){
            throw new BusinessException("参数为空！");
        }

        LambdaUpdateWrapper<SpcyJcyLxjxpgdcb> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcyJcyLxjxpgdcb::getId, buffer.getId());

        SpcyJcyLxjxpgdcb updateBean = new SpcyJcyLxjxpgdcb();
        updateBean.setFyjjy(buffer.getFyjjy());
        spcyJcyLxjxpgdcbService.update(updateBean, updateWrapper);

        /*
        if (StringEmptyUtils.isBlank(buffer.get("id"))){
            throw new BusinessException("参数为空！");
        }
        SpcyJcyLxjxpgdcb updateBean = spcyJcyLxjxpgdcbService.getById(buffer.get("id"));
        if (updateBean == null){
            throw new BusinessException("没有相匹配的数据！");
        }

        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        BeanUtils.populate(updateBean, buffer);
        spcyJcyLxjxpgdcbService.updateById(updateBean);*/
    }

    /**
     * 更新-评估调查表选项
     * @param buffer
     */
    public void updatePgDcbXx(SpcyJcyLxjxpgxx buffer) throws InvocationTargetException, IllegalAccessException {

        if (StringUtils.isBlank(buffer.getId())){
            throw new BusinessException("参数为空！");
        }

        LambdaUpdateWrapper<SpcyJcyLxjxpgxx> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcyJcyLxjxpgxx::getId, buffer.getId());

        SpcyJcyLxjxpgxx updateBean = new SpcyJcyLxjxpgxx();
        updateBean.setFpgjg(buffer.getFpgjg());
        spcyJcyLxjxpgxxService.update(updateBean, updateWrapper);

        /*if (StringEmptyUtils.isBlank(buffer.get("id"))){
            throw new BusinessException("参数为空！");
        }

        SpcyJcyLxjxpgxx updateBean = spcyJcyLxjxpgxxService.getById(buffer.get("id"));
        if (updateBean == null){
            throw new BusinessException("没有相匹配的数据！");
        }

        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        BeanUtils.populate(updateBean, buffer);
        spcyJcyLxjxpgxxService.updateById(updateBean);*/
    }

    /**
     * 更新-教师教学评价
     * @param buffer
     */
    public void updateJsjxpj(HashMap<String,String> buffer) throws InvocationTargetException, IllegalAccessException {
        if (StringEmptyUtils.isBlank(buffer.get("id"))){
            throw new BusinessException("参数为空！");
        }

        SpcyJcyLxjsjxpj updateBean = spcyJcyLxjsjxpjService.getById(buffer.get("id"));
        if (updateBean == null){
            throw new BusinessException("没有相匹配的数据！");
        }

        ConvertUtils.register(new DateConvert(), java.util.Date.class);
        BeanUtils.populate(updateBean, buffer);
        spcyJcyLxjsjxpjService.updateById(updateBean);

    }

    /**
     * 评估调查表-提交
     */
    public void submitPgDcb(String fpgdcbid){
        if (StringUtils.isBlank(fpgdcbid)){
            throw new BusinessException("参数为空！");
        }

        LambdaUpdateWrapper<SpcyJcyLxjxpgdcb> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcyJcyLxjxpgdcb::getId, fpgdcbid);

        SpcyJcyLxjxpgdcb updateBean = new SpcyJcyLxjxpgdcb();
        updateBean.setFtjzt(JcyLxpgDcbConstant.Dcb_Tjzt_Ywc);
        spcyJcyLxjxpgdcbService.update(updateBean, updateWrapper);
    }

    /**
     * 统计教学评估调查结果
     * @param query 应参加评价人数查询条件
     */
    public Map tjJxpgDcJg(String flxjhid, JcyLxUserVo query){
        List<JcyLxUserVo> ycjpjUserList = spcyPxJbxxMapper.selectLxjhUserList(query, new OrderItemVo());

        Map resultMap = new HashMap();

        /** 培训班信息 */
        SpcyPxJbxx lxjh = spcyPxJbxxService.getById(flxjhid);
        Map pxMap = initDcbPxbxxMap(lxjh);


        /** 调查表 */
        List<SpcyJcyLxjxpgdcb> dcbList = spcyJcyLxjxpgdcbService.list(new LambdaQueryWrapper<SpcyJcyLxjxpgdcb>()
                .eq(SpcyJcyLxjxpgdcb::getFlxjhid, flxjhid));
        int ycjpjrs = ycjpjUserList.size(); // 应参加评价人数
        int sjcjpjrs = dcbList.size(); // 实际参加评价人数
        String pjl = StringPatternUtils.CalculatePpercentage(sjcjpjrs, ycjpjrs) + "%"; // 评价率

        pxMap.put("ycjpjrs", ycjpjrs);
        pxMap.put("sjcjpjrs", sjcjpjrs);
        pxMap.put("pjl", pjl);
        resultMap.put("px", pxMap);

        /** 调查表选项-评价结果 */
        CompletableFuture<String> futurePgxx = CompletableFuture.supplyAsync(() -> {

            List<SpcyJcyLxjxpgxx> pgxxList = spcyJcyLxjxpgxxService.list(new LambdaQueryWrapper<SpcyJcyLxjxpgxx>()
                    .eq(SpcyJcyLxjxpgxx::getFlxjhid, flxjhid));
            resultMap.put("xxList", initTjDcbXxListMap(pgxxList, sjcjpjrs));

            return "1";
        }, executor);
        /*List<SpcyJcyLxjxpgxx> pgxxList = spcyJcyLxjxpgxxService.list(new LambdaQueryWrapper<SpcyJcyLxjxpgxx>()
                .eq(SpcyJcyLxjxpgxx::getFlxjhid, flxjhid));
        resultMap.put("xxList", initTjDcbXxListMap(pgxxList, sjcjpjrs));*/


        /** 教师教学评价-评价结果 */
        CompletableFuture<String> futureJsjxpj = CompletableFuture.supplyAsync(() -> {

            resultMap.put("jsjxpjList", initTjDcbJsjxpjListMap(flxjhid, sjcjpjrs));

            return "1";
        }, executor);
//        resultMap.put("jsjxpjList", initTjDcbJsjxpjListMap(flxjhid, sjcjpjrs));

        CompletableFuture<Void> futureAllOf = CompletableFuture.allOf(futurePgxx, futureJsjxpj);
        try {
            futureAllOf.get();// 等待所有结果执行完成
        } catch (InterruptedException e) {
            log.error("[InterruptedException]统计教学评估调查结果: {}", e.getMessage());
        } catch (ExecutionException e) {
            log.error("[ExecutionException]统计教学评估调查结果: {}", e.getMessage());
        }

        return resultMap;
    }

    /**
     * 构建调查表-选项-评价结果
     * @param dcbxxList 调查表选项列表
     * @param sjcjpjrs 实际评价人数
     * */
    private List<Map> initTjDcbXxListMap(List<SpcyJcyLxjxpgxx> dcbxxList, int sjcjpjrs){

        List<Map> resultMapList = new ArrayList<>();

        /*if (CollectionUtil.isEmpty(dcbxxList)){
            return resultMapList;
        }*/

        String[] pgmbBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxmb_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
        String[] pgmbNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxmb_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

        String[] pxfaBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxfa_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
        String[] pxfaNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxfa_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

        String[] pxszBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxsz_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
        String[] pxszNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxsz_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

        String[] pxnrBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxnr_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
        String[] pxnrNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxnr_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

        String[] pxxsBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxxs_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
        String[] pxxsNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxxs_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

        String[] pxzlBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxzl_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
        String[] pxzlNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxzl_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

        String[] xczzBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Xczz_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
        String[] xczzNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Xczz_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

        String[] pxbzBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxbz_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
        String[] pxbzNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Pxbz_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

        String[] xythBtStrings = JcyLxpgDcbConstant.Dcb_Dl_Xyth_Bt.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);
        String[] xythNrStrings = JcyLxpgDcbConstant.Dcb_Dl_Xyth_Nr.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

        String[] pgdlStrings = JcyLxpgDcbConstant.Dcb_Pgdl_List.split(JcyLxpgDcbConstant.Dcb_Split_Gjz);

        for (int order = 0; order < pgdlStrings.length; order++){
            Map dataMap = new HashMap();
            String type = pgdlStrings[order];
            dataMap.put("type", type);

            String[] dctBtStrings = null;
            String[] dctNrStrings = null;

            if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxmb)){
                dctBtStrings = pgmbBtStrings;
                dctNrStrings = pgmbNrStrings;

            }
            else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxfa)){
                dctBtStrings = pxfaBtStrings;
                dctNrStrings = pxfaNrStrings;

            }
            else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxsz)){
                dctBtStrings = pxszBtStrings;
                dctNrStrings = pxszNrStrings;

            }
            else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxnr)){
                dctBtStrings = pxnrBtStrings;
                dctNrStrings = pxnrNrStrings;

            }
            else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxxs)){
                dctBtStrings = pxxsBtStrings;
                dctNrStrings = pxxsNrStrings;

            }
            else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxzl)){
                dctBtStrings = pxzlBtStrings;
                dctNrStrings = pxzlNrStrings;

            }
            else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Xczz)){
                dctBtStrings = xczzBtStrings;
                dctNrStrings = xczzNrStrings;

            }
            else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Pxbz)){
                dctBtStrings = pxbzBtStrings;
                dctNrStrings = pxbzNrStrings;

            }
            else if (type.equals(JcyLxpgDcbConstant.Dcb_Dl_Xyth)){
                dctBtStrings = xythBtStrings;
                dctNrStrings = xythNrStrings;

            }

            List<Map> list = new ArrayList<>();
            if (dctBtStrings != null) {
                for (int j=0; j<dctBtStrings.length; j++) {
                    String title = dctBtStrings[j];
                    Map pjMpa = new HashMap();

                    int mySize = 0;
                    int ybSize = 0;
                    int bmySize = 0;

                    if (CollectionUtil.isNotEmpty(dcbxxList)) {
                        mySize = dcbxxList.stream()
                                .filter(f -> StringUtils.isNotBlank(f.getFpgjg())
                                        && f.getFpgdl().equals(type)
                                        && f.getFpgbt().equals(title)
                                        && f.getFpgjg().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My))
                                .collect(Collectors.toList()).size();

                        ybSize = dcbxxList.stream()
                                .filter(f -> StringUtils.isNotBlank(f.getFpgjg())
                                        && f.getFpgdl().equals(type)
                                        && f.getFpgbt().equals(title)
                                        && f.getFpgjg().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb))
                                .collect(Collectors.toList()).size();

                        bmySize = dcbxxList.stream()
                                .filter(f -> StringUtils.isNotBlank(f.getFpgjg())
                                        && f.getFpgdl().equals(type)
                                        && f.getFpgbt().equals(title)
                                        && f.getFpgjg().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy))
                                .collect(Collectors.toList()).size();
                    }

                    pjMpa.put("id", UUID.randomUUID());
                    pjMpa.put("fpgdl", type);
                    pjMpa.put("fpgbt", title);
                    pjMpa.put("fpgnr", dctNrStrings[j]);

                    pjMpa.put("my", StringPatternUtils.CalculatePpercentage(mySize, sjcjpjrs) + "%");
                    pjMpa.put("yb", StringPatternUtils.CalculatePpercentage(ybSize, sjcjpjrs) + "%");
                    pjMpa.put("bmy", StringPatternUtils.CalculatePpercentage(bmySize, sjcjpjrs) + "%");
                    list.add(pjMpa);
                }
            }

            dataMap.put("list", list);
            resultMapList.add(dataMap);
        }

        return resultMapList;
    }

    /**
     * 构建调查表-教师教学评价-评价结果
     * @param sjcjpjrs 实际评价人数
     * */
    private List<Map> initTjDcbJsjxpjListMap(String flxjhid, int sjcjpjrs){
        List<Map> resultMapList = new ArrayList<>();

        // 培训老师列表
        List<SpcyJcyLxpxls> pxlsBeanList = spcyJcyLxpxlsService.getPxlsList(flxjhid);
        if (CollectionUtil.isEmpty(pxlsBeanList)){
            return resultMapList;
        }

        List<String> pxlsNameList = new ArrayList<>();
        for (SpcyJcyLxpxls pxls : pxlsBeanList){
            String name = pxls.getFjsxm();

            /** 教学态度 */
            int fjxtd_mySize = 0;
            int fjxtd_ybSize = 0;
            int fjxtd_bmySize = 0;

            /** 教学内容针对性 */
            int fjxnrzdx_mySize = 0;
            int fjxnrzdx_ybSize = 0;
            int fjxnrzdx_bmySize = 0;

            /** 教学技巧与方法 */
            int fjxjqyff_mySize = 0;
            int fjxjqyff_ybSize = 0;
            int fjxjqyff_bmySize = 0;

            /** 讲解突出重点难点 */
            int fjjtczdnd_mySize = 0;
            int fjjtczdnd_ybSize = 0;
            int fjjtczdnd_bmySize = 0;

            /** 教学效果 */
            int fjxxg_mySize = 0;
            int fjxxg_ybSize = 0;
            int fjxxg_bmySize = 0;

            if (pxlsNameList.contains(name)){
                continue;
            }

            // 教师评价结果
            List<SpcyJcyLxjsjxpj> jsjxpjList = spcyJcyLxjsjxpjService.list(new LambdaQueryWrapper<SpcyJcyLxjsjxpj>()
                    .in(SpcyJcyLxjsjxpj::getFpxlsid, pxls.getId()));
            if (CollectionUtil.isNotEmpty(jsjxpjList)){
                /** 教学态度 */
                fjxtd_mySize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxtd())
                                && f.getFjxtd().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My))
                        .collect(Collectors.toList()).size();

                fjxtd_ybSize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxtd())
                                && f.getFjxtd().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb))
                        .collect(Collectors.toList()).size();

                fjxtd_bmySize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxtd())
                                && f.getFjxtd().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy))
                        .collect(Collectors.toList()).size();

                /** 教学内容针对性 */
                fjxnrzdx_mySize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxnrzdx())
                                && f.getFjxnrzdx().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My))
                        .collect(Collectors.toList()).size();

                fjxnrzdx_ybSize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxnrzdx())
                                && f.getFjxnrzdx().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb))
                        .collect(Collectors.toList()).size();

                fjxnrzdx_bmySize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxnrzdx())
                                && f.getFjxnrzdx().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy))
                        .collect(Collectors.toList()).size();

                /** 教学技巧与方法 */
                fjxjqyff_mySize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxjqyff())
                                && f.getFjxjqyff().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My))
                        .collect(Collectors.toList()).size();

                fjxjqyff_ybSize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxjqyff())
                                && f.getFjxjqyff().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb))
                        .collect(Collectors.toList()).size();

                fjxjqyff_bmySize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxjqyff())
                                && f.getFjxjqyff().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy))
                        .collect(Collectors.toList()).size();

                /** 讲解突出重点难点 */
                fjjtczdnd_mySize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjjtczdnd())
                                && f.getFjjtczdnd().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My))
                        .collect(Collectors.toList()).size();

                fjjtczdnd_ybSize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjjtczdnd())
                                && f.getFjjtczdnd().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb))
                        .collect(Collectors.toList()).size();

                fjjtczdnd_bmySize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjjtczdnd())
                                && f.getFjjtczdnd().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy))
                        .collect(Collectors.toList()).size();

                /** 教学效果 */
                fjxxg_mySize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxxg())
                                && f.getFjxxg().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My))
                        .collect(Collectors.toList()).size();

                fjxxg_ybSize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxxg())
                                && f.getFjxxg().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb))
                        .collect(Collectors.toList()).size();

                fjxxg_bmySize = jsjxpjList.stream()
                        .filter(f->StringUtils.isNotBlank(f.getFjxxg())
                                && f.getFjxxg().equals(JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy))
                        .collect(Collectors.toList()).size();

            }

            Map jsjxpjMap = new HashMap();

            List<Map> pxnrList = new ArrayList<>();
            pxnrList = initDcbJsjxPjNrListMap(pxnrList, flxjhid, name);

            jsjxpjMap.put("name", name);
            jsjxpjMap.put("pxnrList", pxnrList);

            /** 教学态度 */
            String fjxtd = "";
            fjxtd += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My + "（" + StringPatternUtils.CalculatePpercentage(fjxtd_mySize, sjcjpjrs) + "%" + "）";
            fjxtd += "@";
            fjxtd += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb + "（" + StringPatternUtils.CalculatePpercentage(fjxtd_ybSize, sjcjpjrs) + "%" + "）";
            fjxtd += "@";
            fjxtd += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy + "（" + StringPatternUtils.CalculatePpercentage(fjxtd_bmySize, sjcjpjrs) + "%" + "）";

            /** 教学内容针对性 */
            String fjxnrzdx = "";
            fjxnrzdx += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My + "（" + StringPatternUtils.CalculatePpercentage(fjxnrzdx_mySize, sjcjpjrs) + "%" + "）";
            fjxnrzdx += "@";
            fjxnrzdx += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb + "（" + StringPatternUtils.CalculatePpercentage(fjxnrzdx_ybSize, sjcjpjrs) + "%" + "）";
            fjxnrzdx += "@";
            fjxnrzdx += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy + "（" + StringPatternUtils.CalculatePpercentage(fjxnrzdx_bmySize, sjcjpjrs) + "%" + "）";

            /** 教学技巧与方法 */
            String fjxjqyff = "";
            fjxjqyff += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My + "（" + StringPatternUtils.CalculatePpercentage(fjxjqyff_mySize, sjcjpjrs) + "%" + "）";
            fjxjqyff += "@";
            fjxjqyff += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb + "（" + StringPatternUtils.CalculatePpercentage(fjxjqyff_ybSize, sjcjpjrs) + "%" + "）";
            fjxjqyff += "@";
            fjxjqyff += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy + "（" + StringPatternUtils.CalculatePpercentage(fjxjqyff_bmySize, sjcjpjrs) + "%" + "）";

            /** 讲解突出重点难点 */
            String fjjtczdnd = "";
            fjjtczdnd += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My + "（" + StringPatternUtils.CalculatePpercentage(fjjtczdnd_mySize, sjcjpjrs) + "%" + "）";
            fjjtczdnd += "@";
            fjjtczdnd += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb + "（" + StringPatternUtils.CalculatePpercentage(fjjtczdnd_ybSize, sjcjpjrs) + "%" + "）";
            fjjtczdnd += "@";
            fjjtczdnd += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy + "（" + StringPatternUtils.CalculatePpercentage(fjjtczdnd_bmySize, sjcjpjrs) + "%" + "）";

            /** 教学效果 */
            String fjxxg = "";
            fjxxg += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_My + "（" + StringPatternUtils.CalculatePpercentage(fjxxg_mySize, sjcjpjrs) + "%" + "）";
            fjxxg += "@";
            fjxxg += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Yb + "（" + StringPatternUtils.CalculatePpercentage(fjxxg_ybSize, sjcjpjrs) + "%" + "）";
            fjxxg += "@";
            fjxxg += JcyLxpgDcbConstant.Dcb_Xx_Pgjg_Lx_Bmy + "（" + StringPatternUtils.CalculatePpercentage(fjxxg_bmySize, sjcjpjrs) + "%" + "）";

            // 教师评价结果内容
            Map resultPjnrMap = new HashMap();
            resultPjnrMap.put("id", UUID.randomUUID());
            resultPjnrMap.put("fjxtd", fjxtd);
            resultPjnrMap.put("fjxnrzdx", fjxnrzdx);
            resultPjnrMap.put("fjxjqyff", fjxjqyff);
            resultPjnrMap.put("fjjtczdnd", fjjtczdnd);
            resultPjnrMap.put("fjxxg", fjxxg);

            jsjxpjMap.put("pjnr", resultPjnrMap);

            pxlsNameList.add(name);
            resultMapList.add(jsjxpjMap);
        }

        return resultMapList;
    }

    /**
     * 获取调查表-根据遴选id和用户id
     */
    public SpcyJcyLxjxpgdcb getDcbByUserId(String flxjhid, String userid){
        List<SpcyJcyLxjxpgdcb> list = spcyJcyLxjxpgdcbService.list(new LambdaQueryWrapper<SpcyJcyLxjxpgdcb>()
                .eq(SpcyJcyLxjxpgdcb::getFlxjhid, flxjhid)
                .eq(SpcyJcyLxjxpgdcb::getFpjrid, userid));
        if (CollectionUtil.isNotEmpty(list)){
            return list.get(0);
        }

        return null;
    }
}
